package com.kust.smarthome.web.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kust.smarthome.web.dto.OrderDto;
import com.kust.smarthome.web.dto.OrderDto2;
import com.kust.smarthome.web.mapper.OrderFormMapper;
import com.kust.smarthome.web.model.OrderForm;
import com.kust.smarthome.web.service.IOrderFormService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author iAuzre
 * @since 2021-07-09
 */
@Service
public class OrderFormServiceImpl extends ServiceImpl<OrderFormMapper, OrderForm> implements IOrderFormService {

    @Autowired
    private OrderFormMapper orderFormMapper;

    @Override
    public boolean insert(OrderForm order) {
        orderFormMapper.insert(order);
        return true;
    }

    @Override
    public List<OrderDto> getState0ByUserId(Integer userId) {

        List<OrderDto> list = orderFormMapper.selectState0ByUserId(userId);
        return list;
    }

    @Override
    public List<OrderDto> getState1ByUserId(Integer userId) {
        List<OrderDto> list = orderFormMapper.selectState1ByUserId(userId);
        return list;
    }

    @Override
    public List<OrderDto> getState2ByUserId(Integer userId) {
        List<OrderDto> list = orderFormMapper.selectState2ByUserId(userId);
        return list;
    }

    @Override
    public List<OrderDto> getState3ByUserId(Integer userId) {
        List<OrderDto> list = orderFormMapper.selectState3ByUserId(userId);
        return list;
    }

    @Override
    public List<OrderDto> getState4ByUserId(Integer userId) {
        List<OrderDto> list = orderFormMapper.selectState4ByUserId(userId);
        return list;
    }

    @Override
    public List<OrderDto> getAll(Integer id) {
        return orderFormMapper.selectAll(id);
    }

    @Override
    public List<OrderDto2> getAll2(Integer id) {
        return orderFormMapper.selectAll2(id);
    }

    @Override
    public boolean deleteOrder(Integer userId, String id) {
        QueryWrapper<OrderForm> query = new QueryWrapper<>();
        query.eq("user_id",userId);
        query.eq("id",id);
        return orderFormMapper.delete(query) == 1;
    }

    @Override
    public OrderForm getOrderByID(String id) {
        QueryWrapper<OrderForm> query = new QueryWrapper<>();
        query.eq("id",id);
        return orderFormMapper.selectById(id);
    }
}
